package com.w.picture.api.imagesrarch;

import com.w.picture.api.imagesrarch.model.ImageSearchResult;
import com.w.picture.api.imagesrarch.model.sub.GetImageFirstUrlApi;
import com.w.picture.api.imagesrarch.model.sub.GetImageListApi;
import com.w.picture.api.imagesrarch.model.sub.GetImagePageUrlApi;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 图片搜索api门面
 * 通过门面模式提供统一的接口来简化多个接口的调用,使客户端不需要关心多个接口的细节
 * @author wzp
 * @since 2025/1/23
 */
@Slf4j
public class ImageSearchApiFacade {

    /**
     * 搜索图片
     *
     * @param imageUrl
     * @return
     */
    public static List<ImageSearchResult> searchImage(String imageUrl) {
        // 获取图片的页面地址
        String imagePageUrl = GetImagePageUrlApi.getImagePageUrl(imageUrl);
        // 根据得到的页面地址获取查询的图片列表的地址
        String imageFirstUrl = GetImageFirstUrlApi.getImageFirstUrl(imagePageUrl);
        // 根据得到的图片列表地址获取图片列表
        List<ImageSearchResult> imageList = GetImageListApi.getImageList(imageFirstUrl);
        return imageList;
    }

    public static void main(String[] args) {
        // 测试以图搜图功能
        String imageUrl = "https://www.codefather.cn/logo.png";
        List<ImageSearchResult> resultList = searchImage(imageUrl);
        System.out.println("结果列表" + resultList);
    }
}

